
package com.rx.mgt.controller;  

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rx.mgt.po.UserMailInfoCountBo;
import com.rx.mgt.po.UsersBo;
import com.rx.mgt.service.AdminUserService;
import com.rx.mgt.service.DomainInfoExtService;
import com.rx.mgt.service.UserInfoExtService;
import com.rx.mgt.service.UserMailInfoService;
import com.rx.mgt.util.DateUtil;

/** 
 * ClassName:IndexController 
 * Function :
 * Reason   : 
 * Date     :Feb 7, 2017 2:46:50 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */

@Controller
public class IndexController {
    private static Logger logger = Logger.getLogger(IndexController.class);
    @Autowired
    AdminUserService adminUserService;
    @Autowired
    UserInfoExtService userInfoExtService;
    @Autowired
    DomainInfoExtService domainInfoExtService;
    @Autowired
    UserMailInfoService userMailInfoService;
    @RequestMapping(value="/welcome.htmlx")
    public String  welcome(ModelMap model){
       
        UsersBo usersBo = new UsersBo();
//        usersBo.setType("");
        usersBo.setStartDate(DateUtil.getCurrentDateStartTime());
        logger.info("=============="+usersBo);
        logger.debug("=============="+usersBo);
        setTodayInfo(model, usersBo);;
        usersBo.setStartDate(DateUtil.getWeekStartDate());
        setWeekInfo(model, usersBo);
        usersBo.setStartDate(DateUtil.getMonthStartDate());
        setmonthInfo(model, usersBo);
        return "welcome";
    }
    public void setTodayInfo(ModelMap model,UsersBo usersBo){
        Long todayAdminUserCount = adminUserService.getAdminUserCount(usersBo);
        Long todayUserInfoExtCount = userInfoExtService.getUserInfoExtCount(usersBo);
        Long todayDomainInfoExtCount = domainInfoExtService.getDomainInfoExtCount(usersBo);
        List<UserMailInfoCountBo> todayUserMailInfoCount = userMailInfoService.getUserMailInfoCount(usersBo);
        model.addAttribute("todayAdminUserCount", todayAdminUserCount);
        model.addAttribute("todayUserInfoExtCount", todayUserInfoExtCount);
        model.addAttribute("todayDomainInfoExtCount", todayDomainInfoExtCount);
        model.addAttribute("todayMsgCount", todayUserMailInfoCount.get(0).getMsgCount());
        model.addAttribute("todayMsgSize", todayUserMailInfoCount.get(0).getMsgSize());
    }
    public void setWeekInfo(ModelMap model,UsersBo usersBo){
        Long weekAdminUserCount = adminUserService.getAdminUserCount(usersBo);
        Long weekUserInfoExtCount = userInfoExtService.getUserInfoExtCount(usersBo);
        Long weekDomainInfoExtCount = domainInfoExtService.getDomainInfoExtCount(usersBo);
        List<UserMailInfoCountBo> weekUserMailInfoCount = userMailInfoService.getUserMailInfoCount(usersBo);
        model.addAttribute("weekAdminUserCount", weekAdminUserCount);
        model.addAttribute("weekUserInfoExtCount", weekUserInfoExtCount);
        model.addAttribute("weekDomainInfoExtCount", weekDomainInfoExtCount);
        model.addAttribute("weekMsgCount", weekUserMailInfoCount.get(0).getMsgCount());
        model.addAttribute("weekMsgSize", weekUserMailInfoCount.get(0).getMsgSize());
    }
    public void setmonthInfo(ModelMap model,UsersBo usersBo){
        Long monthAdminUserCount = adminUserService.getAdminUserCount(usersBo);
        Long monthUserInfoExtCount = userInfoExtService.getUserInfoExtCount(usersBo);
        Long monthDomainInfoExtCount = domainInfoExtService.getDomainInfoExtCount(usersBo);
        List<UserMailInfoCountBo> monthUserMailInfoCount = userMailInfoService.getUserMailInfoCount(usersBo);
        model.addAttribute("monthAdminUserCount", monthAdminUserCount);
        model.addAttribute("monthUserInfoExtCount", monthUserInfoExtCount);
        model.addAttribute("monthDomainInfoExtCount", monthDomainInfoExtCount);
        model.addAttribute("monthMsgCount", monthUserMailInfoCount.get(0).getMsgCount());
        model.addAttribute("monthMsgSize", monthUserMailInfoCount.get(0).getMsgSize());
    }
}

  